﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Xunit;
using YAPL.Language.SourceParser;
using YAPL.Language.Ast;
using YAPL.Language.SourceParser.XML;

namespace YAPL.Test.YAPL.Language.Parser.XML.NodeParsers {
	public class XmlProgramDefParserTest : XmlNodeParserTest {

		[Fact]
		public void ProgramShouldContainCodeBlock() {
			var programDefNode = new XElement(XmlNames.ProgramDefExpression);
			Assert.Throws<ArgumentNullException>(() => _parser.ParseNode(programDefNode));
		}

		[Fact]
		public void EmptyProgramShouldBeParsedCorrectly() {
			var programDefNode = new XElement(XmlNames.ProgramDefExpression, new XElement(XmlNames.CodeBlockExpression));
			var expr = _parser.ParseNode(programDefNode);
			Assert.IsType(typeof(ProgramDefExpression), expr);
			var programDef = (ProgramDefExpression) expr;
			Assert.NotNull(programDef.ProgramBody);
			Assert.Empty(programDef.ProgramBody.Expressions);
		}
	}
}